from django.db import models
from django.utils import timezone
from tinymce.models import HTMLField

class MyNew(models.Model):
    NEWS_CHOICES = (
        ('企业要闻', '企业要闻'),
        ('行业新闻', '行业新闻'),
        ('通知公告', '通知公告'),
    )
    title = models.CharField(max_length=50, verbose_name='新闻标题')
    description = HTMLField(verbose_name='新闻内容')  
    publishDate = models.DateTimeField(default=timezone.now,
                                       verbose_name='发布时间')
    NEW_TYPE_DEFAULT = '企业要闻'
    newType = models.CharField(choices=NEWS_CHOICES,
                               max_length=50,
                               verbose_name='新闻类型',
                               default=NEW_TYPE_DEFAULT)
    views = models.PositiveIntegerField('浏览量', default=0)
    photo = models.ImageField(upload_to='news/',
                              blank=True,
                              null=True,
                              verbose_name='展报')

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = '新闻'
        verbose_name_plural = '新闻'
        ordering = ('-publishDate', )
